﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace _004_坦克大战_正式
{
    public partial class Form1 : Form
    {
        private Thread t;
        private static Graphics windowsG;
        private static Bitmap tampBmp;

        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;

            windowsG = this.CreateGraphics();
            //GameFramework.g = g;

            tampBmp = new Bitmap(390, 390);
            Graphics bmpG = Graphics.FromImage(tampBmp);
            GameFramework.g = bmpG;


            t = new Thread(new ThreadStart(GameMainThread));
            t.Start();


        }
        private static void GameMainThread()
        {
            //GameFramework

            int sleepTime = 1000 / 60;

            GameFramework.Start();

            

            while (true)
            {

                GameFramework.g.Clear(Color.Black);

                GameFramework.Update();

                windowsG.DrawImage(tampBmp, 0, 0);

                Thread.Sleep(sleepTime);
            }
        }

        

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            GameObjectManager.KeyDown(e);
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            GameObjectManager.KeyUp(e);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            t.Abort();
        }
    }
}
